<template>
    <div class="ware_house_type_form_container">
        <el-form ref="wareHouseTypeorm" :model="formData" :rules="rules" label-width="80px">
            <el-form-item label="编号" prop="value">
                <el-input v-model="formData.value" placeholder="请输入编号" clearable/>
            </el-form-item>
            <el-form-item label="名称" prop="display_text">
                <el-input v-model="formData.display_text" placeholder="请输入名称"/>
            </el-form-item>
            <el-form-item label="备注" prop="note_info">
                <el-input type="textarea" v-model="formData.note_info" placeholder="请输入备注"
                          maxlength="200" show-word-limit clearable/>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    name: "WareHouseTypeForm",
    props: {
        row: {
            type: Object,
            default: null,
        },
    },
    data () {
        return {
            formData: {},
            rules: {
                value: [{required: true, message: '请输入编号', trigger: 'blur'}],
                display_text: [{required: true, message: '请输入名称', trigger: 'blur'}],
            },
        }
    },
    watch: {
        row: {
            handler () {
                this.init();
            },
            deep: true,
            immediate: true,
        },
    },
    methods: {
        init () {
            const _this = this;
            if (!_this.row) {
                return;
            }
            if (_this.$refs.wareHouseTypeorm) {
                _this.$refs.wareHouseTypeorm.clearValidate();
            }
            _this.formData = $.extend({}, _this.row);
        },
        async confirm () {
            const _this = this;
            let valid = await _this.validateForm('wareHouseTypeorm');
            if (!valid) {
                return false;
            }
            let subData = $.extend({}, _this.formData);
            subData.name = '进销存-仓库管理-仓库类型';
            subData.key1 = _this.$api.STOCK_WAREHOUSE_TYPE_KEY;
            return _this.fetchData(_this.$api.API_SaveCommonParameterValue, subData).then(() => {
                _this.$message.success('保存成功！');
                return true;
            }).catch(() => {
                return false;
            });
        },
    },
}
</script>

<style lang="less" rel="stylesheet/less" scoped>
.ware_house_type_form_container {
    width: 100%;
    height: 100%;
    overflow: hidden;
}
</style>
